<?php
/**
 * Created by PhpStorm.
 * User: alinejun
 * Date: 2019/1/6
 * Time: 19:33
 */
namespace app\common\model;
use think\Db;

class User extends ModelBase{
    public function search($where = [], $field = true, $order = '', $paginate = 0)
    {
        $list = $this->getList($where, $field, $order, $paginate);
        return $list;
    }
    public function del($where = [], $field = '', $value = ''){
       return  $this->setFieldValue($where,$field,$value);
    }

    public function add($data)
    {
        if(isset($data['password_confirm'])){
            unset($data['password_confirm']);
        }
        $data['create_time'] = time();
        $data['password'] = md5($data['password'].config('password_token'));
        $data['balance'] = 1000;
        $res = Db::name('user')->insert($data);
        return $res;
    }

    public function getUserInfo($where)
    {
        $res = Db::name('user')->where($where)->find();
        return $res;
    }

    public function updateBalance($userid,$money,$type=1)
    {
        if($type){
            $res = $this->where(['id'=>$userid])->setDec('balance',$money);
        }
        return $res;
    }
}